#include "bsp_timer6.h"
#include "at32f403a_407.h"
#include "cbb_init.h"

#include "lvgl.h"

void bsp_timer6_init(void){

    crm_periph_clock_enable(CRM_TMR6_PERIPH_CLOCK, TRUE);
    
    tmr_cnt_dir_set(TMR6, TMR_COUNT_UP);
    tmr_period_buffer_enable(TMR6, FALSE);
    tmr_primary_mode_select(TMR6, TMR_PRIMARY_SEL_RESET);
    
    tmr_counter_enable(TMR6, TRUE);
    tmr_base_init(TMR6, 1000-1, 240-1); 
    
    nvic_irq_enable(TMR6_GLOBAL_IRQn, 0, 0);
    
    tmr_interrupt_enable(TMR6, TMR_OVF_INT, TRUE);
    
}
INIT_PORT_BSP(bsp_timer6_init);
    
void TMR6_GLOBAL_IRQHandler(void){

    if(TMR6->ists_bit.ovfif == 1){


        lv_tick_inc(1);

        TMR6->ists_bit.ovfif = 0;

    }
} 
